﻿using Microsoft.AspNetCore.SignalR;
using Quantum.Core;

namespace Quantum.SignalR
{
    public class AbstractAuthenticatedReplier : Hub, IReplyBehavior, IAuthenticateBehavior
    {
        protected void Reply<T>(T outgoingMessage)
        {
            Clients.Client(Context.ConnectionId).InvokeAsync("Send", outgoingMessage);
        }
        
        public virtual void Send(string incomingMessage)
        {
            var authenticated = Authenticate(incomingMessage);
            if (authenticated)
            {
                Reply(incomingMessage);
            }
            else
            {
                Reply("验证失败！");
            }
        }

        public virtual bool Authenticate(string incomingMessage)
        {
            return false;
        }

        //public virtual bool Authenticate<T>(Outgoing<T> incomingMessage)
        //{
        //    return false;
        //}
    }
}
